/**
 *  Verschieben von Vorlesungen zwischen den Boxen
 */

function moveSelectedItems(source, destination){
    var selected = $(source+' option:selected').remove();
    var sorted = $.makeArray($(destination+' option').add(selected)).sort(function(a,b){
        return $(a).text() > $(b).text() ? 1:-1;
    });
    $(destination).empty().append(sorted);
}

$(document).ready(function(){
    $('#lectures-add').click(function(){
        moveSelectedItems('#lectures-available', '#lectures-selected');
    });

    $('#lectures-remove').click(function(){
        moveSelectedItems('#lectures-selected', '#lectures-available');
    });
    $('#createform').submit(function(){
        $('#lectures-selected option').attr('selected', 'true');
    });
});


